//package guo.controller;
//
//import guo.bean.JavaBeanTest;
//import guo.factoryBean.JavaFactoryBeanTest;
//import guo.util.R;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.ApplicationContext;
//import org.springframework.context.annotation.AnnotationConfigApplicationContext;
//import org.springframework.context.support.ClassPathXmlApplicationContext;
//import org.springframework.stereotype.Controller;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.ResponseBody;
//import org.springframework.web.context.WebApplicationContext;
//import third.pojo.ThirdPojo;
//
//import java.lang.annotation.Annotation;
//import java.lang.reflect.Field;
//import java.lang.reflect.Method;
//import java.util.concurrent.CompletableFuture;
//import java.util.concurrent.ExecutionException;
//import java.util.concurrent.ThreadPoolExecutor;
//
//@Controller
//public class TestExecutor {
//
//    @Autowired
//    private ApplicationContext applicationContext;
//
//    @Autowired
//    private ThreadPoolExecutor executor;
//
//    @GetMapping("/executor1")
//    @ResponseBody
//    public R egy(){
//
//        CompletableFuture.runAsync(()->{
//            for(int i = 0;i < 100;i++){
//                System.out.println("这是第一个线程 "+i);
//            }
//        },executor).whenCompleteAsync((res,exc)->{
//            System.out.println("线程执行的结果是 "+res);
//            System.out.println("线程执行的异常是 "+exc);
//        });
//        CompletableFuture.runAsync(()->{
//            for(int i = 0;i < 100;i++){
//                System.out.println("*************"+i);
//            }
//        },executor);
//        return R.ok();
//    }
//
//
//    @GetMapping("/executor2")
//    @ResponseBody
//    public R egy2() throws ExecutionException, InterruptedException {
//
//        CompletableFuture<Integer[]> f1 = CompletableFuture.supplyAsync(() -> {
//            Integer[] ints = new Integer[10];
//            System.out.println(ints);
//            return ints;
//        }, executor).exceptionally(exc -> {
//            System.out.println(exc);
//            Integer[] iniis = new Integer[5];
//            System.out.println(iniis);
//            return iniis;
//        });
//
//        Integer[] integers = f1.get();
//        System.out.println("最终结果为 "+integers);
//
//        CompletableFuture.allOf(f1);
//        return R.ok();
//    }
//
//    /**
//     * 线程串行化
//     * @return
//     */
//    @GetMapping("/executor3")
//    @ResponseBody
//    public R Executor3() throws ExecutionException, InterruptedException {
//
//        CompletableFuture.runAsync(()->{
//            int i = 10;
//            System.out.println("第一个线程池的运算结果为 "+i);
//        },executor).thenRunAsync(()->{
//            System.out.println("第二个线程池运算");
//        },executor);
//
//
//        CompletableFuture<Integer> f2 = CompletableFuture.supplyAsync(() -> {
//
//            int i = 10 / 5;
//            System.out.println("第一个返回值 " + i);
//            return i;
//        }, executor).thenApplyAsync(res -> {
//            System.out.println("第二个返回值得到的值为 " + res);
//            return 555;
//        }, executor);
//
//        Integer integer = f2.get();
//        System.out.println("f2得到的最终值为 "+integer);
//        return R.ok();
//    }
//
//
//    @GetMapping("/executor4")
//    @ResponseBody
//    public R getExecutor4() throws Exception {
//
//        CompletableFuture<Void> f1 = CompletableFuture.runAsync(() -> {
//            System.out.println("第一个线程执行了");
//        }, executor);
//
//        CompletableFuture<Void> f2 = CompletableFuture.runAsync(() -> {
//            System.out.println("第二个线程执行了");
//        }, executor);
//
//        CompletableFuture<Void> future = f1.runAfterBoth(f2,()->{
//            System.out.println("第三个线程执行了");
//        });
//
//
////        ApplicationContext context = new ClassPathXmlApplicationContext("spring-05.xml");
////        ThirdPojo pojo = context.getBean(ThirdPojo.class);
////        System.out.println(pojo);
////        System.out.println("***************");
//////
////        Object bean = context.getBean("&factoryBeanTest");
////        System.out.println(bean);
////        Object bean1 = context.getBean("factoryBeanTest");
////        System.out.println(bean1);
////        String[] beanDefinitionNames = context.getBeanDefinitionNames();
////
////        System.out.println(beanDefinitionNames.length);
////        for (String s:beanDefinitionNames){
////            System.out.println(s);
////        }
//
////        ApplicationContext context = new AnnotationConfigApplicationContext();
////        String[] names = context.getBeanDefinitionNames();
////        for (int i = 0;i < names.length;i++){
////            System.out.println(names[i].toString());
////        }
////        System.out.println(names.length);
//
////
////        ApplicationContext context = new ServletWebServerApplicationContext();
////        String[] names = context.getBeanDefinitionNames();
////        System.out.println(names.length);
//
//
//        String[] beanDefinitionNames = applicationContext.getBeanDefinitionNames();
//        System.out.println(beanDefinitionNames.length);
//
//        for (String s:beanDefinitionNames) {
//            System.out.println(s);
//        }
//
////        System.out.println("************************");
//
////        Object test = applicationContext.getBean("javaFactoryBeanTest");
////        System.out.println(test);   //guo.bean.JavaBeanTest@4c858f1b
////        Object bean = applicationContext.getBean("&javaFactoryBeanTest");
////        System.out.println(bean);  //guo.factoryBean.JavaFactoryBeanTest@609e18c
//
////        Object contextBean = applicationContext.getBean("threadPoolExecutorCom");
////        Annotation[] annotations = contextBean.getClass().getDeclaredAnnotations();
////        Field[] declaredField = contextBean.getClass().getFields();
////        Method[] declaredMethods = contextBean.getClass().getMethods();
////
////        for (Annotation annotation:annotations){
////            System.out.println(annotation);
////        }
//
//
//
////
////        ApplicationContext context = new AnnotationConfigServletWebApplicationContext();
////        String[] names = context.getBeanDefinitionNames();
////        System.out.println(names.length);
//
//        return R.ok();
//    }
//}